$(function () {
    $("#top").click(function () {
        var id = $("#postId").val();
        $.post(
            CONTEXT_PATH + "/discuss/top/" + id,
            function (data) {
                if (data.code === 200) {
                    $("#top").attr('disabled', 'disabled')
                } else {
                    alert(data.msg)
                }
            }
        )
    })
    $("#wonderful").click(function () {
        var id = $("#postId").val();
        $.post(
            CONTEXT_PATH + "/discuss/wonderful/" + id,
            function (data) {
                if (data.code === 200) {
                    $("#wonderful").attr('disabled', 'disabled')
                } else {
                    alert(data.msg)
                }
            }
        )
    })
    $("#delete").click(function () {
        var id = $("#postId").val();
        $.ajax({
            url: CONTEXT_PATH + "/discuss/" + id,
            type: 'delete',
            success: function (data) {
                if (data.code === 200) {
                    window.location.href = CONTEXT_PATH
                } else {
                    alert(data.msg)
                }
            }
        })
    })
})
function like(btn,entityType, entityId, entityUserId, postId) {
    $.post(
        CONTEXT_PATH + "/like",
        {
            entityType: entityType,
            entityId: entityId,
            entityUserId: entityUserId,
            postId: postId,
        },
        function (data) {
            if (data.code === 200) {
                $(btn).children("b").text(data.likeStatus===1?"已赞":"赞");
                $(btn).children("i").text(data.likeCount);
            } else {
                alert(data.msg);
            }
        }
    )
}
